#pragma once

#include "../os/platform.h"
#include "../utils/cmdline.h"
#include "IBenchmark.h"
#include "result.h"
#include <vector>

#define PBENCH_VERSION      1
                       

//
// CResultWriterFile
//

class CResultWriterFile: public IResultWriter
{       
public:
    CResultWriterFile(FILE *out);

    virtual void WriteInfo(const RESULTSFILEINFO *info);

    virtual void BeginModule(const char *modulename);
    virtual void WriteNode(const char *name, float value);
    virtual void EndModule();

private:
    FILE *m_Out;
};

//
// CResultWriterMemory
//

class CResultWriterMemory: public IResultWriter
{      
public:
    CResultWriterMemory();

    virtual void WriteInfo(const RESULTSFILEINFO *info);

    virtual void BeginModule(const char *modulename);
    virtual void WriteNode(const char *name, float value);
    virtual void EndModule();
    
    void SetVerboseMode(bool verbose) { m_Verbose = verbose; }
    void WriteConfig(const char *filename);

    static void Merge(const CResultWriterMemory *results, int size, IResultWriter *out);
    

private:

    struct MODULE
    {
        struct NODE
        {
            CChString name;
            float value;
        };

        std::vector<NODE> nodes;
        CChString name;
    };

    RESULTSFILEINFO     m_Info;

    std::vector<MODULE> m_Modules;
    bool                m_Verbose;      //nem csak a memoriaba irja, hanem az stdout-ra is
};


//
// CBenchmark - akar singleton is lehetne
//

class CBenchmark
{
public:
    CBenchmark(const CCmdlineArgs *args);
    ~CBenchmark();

    void Add(IBenchmark *p);    // p-t a Cleanup() szabaditja fel
    void Cleanup();

    void Run(const RESULTSFILEINFO *info, IResultWriter *results);

private:                                  
    std::vector<IBenchmark*> m_Benchmarks;
    const CCmdlineArgs      *m_Args;
};
